<template>
	<view class="container">
		<view class="logo-wrap flex justify-center align-center flex-direction">
			<image class="logo" src="/static/logo.png" mode="widthFix"></image>
			<view class="name">App名称</view>
			<view class="version">版本 {{ appVersion }}</view>
		</view>

		<u-cell-group>
			<u-cell @click="updateApp" size="large" isLink title="版本更新"></u-cell>
			<u-cell @click="updateApp" label="跳转对应应用市场" value="iOS/Android通用" size="large" isLink title="版本更新"></u-cell>
		</u-cell-group>
		<view style="height: 16rpx;"></view>
		<u-cell-group>
			<u-cell @click="handleRouter(3)" size="large" isLink title="调用微信分享"></u-cell>
			<u-cell @click="handleRouter(4)" size="large" isLink title="调用系统分享"></u-cell>
		</u-cell-group>
		
		<view class="about-footer">
			<view class="flex justify-center align-center">
				<text @click="handleRouter(0)" class="url margin-right-sm">用户协议</text>
				<u-line color="#888888" length="12px" direction="col"></u-line>
				<text @click="handleRouter(1)" class="url margin-left-sm">隐私条例</text>
			</view>

			<view class="service flex justify-center align-center flex-direction">
				<!-- <view @click="copyItem('12345@qq.com', 0)">举报邮箱：12345@qq.com</view> -->
				<!-- <view style="margin:12rpx 0;"  @click="copyItem('028-88888888', 1)">举报电话：028-88888888</view> -->
				<view @click="icpUrl" class="icp-url flex justify-center align-center">
					ICP 备案号：蜀ICP备11111111号-01
				</view>
			</view>
			<view class="copyright">
				Copyright © 2008-{{ year }} App名称 All Rights Reserved.
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				year: 2023,
				appVersion: '1.0.0',
			};
		},
		onLoad() {
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, wgtinfo => {
				this.appVersion = wgtinfo.version;
			});
			// #endif
			
			// 获取当前年份
			let date = new Date();
			this.year = date.getFullYear();
		},
		methods: {
			// 复制
			copyItem(item, index) {
				if (!item) return;
				switch (index) {
					case 0:
						uni.setClipboardData({
							data: item,
							showToast: false,
							success: () => {
								uni.showToast({
									title: '客服邮箱复制成功',
									icon: 'none'
								})
							}
						});
						break;
					case 1:
						uni.makePhoneCall({
							phoneNumber: item
						});
						break;
					default:
						break;
				}
			},

			/**
			 * 版本更新
			 * @param
			 * @return
			 */
			updateApp() {
				// #ifdef APP-PLUS
				if (uni.getSystemInfoSync().platform == "ios") {
					let appleId = 12345678;
					plus.runtime.launchApplication({
						action: `itms-apps://itunes.apple.com/cn/app/id${appleId}`,
					})
				} else if (uni.getSystemInfoSync().platform == "android") {
					// 这个是通用应用市场，如果想指定某个应用商店，需要单独查这个应用商店的包名或scheme及参数
					// 包名 com.xxxx.xxxxx
					let appurl = "market://details?id=com.xxxx.xxxxx";
					plus.runtime.openURL(appurl);
				}
				// #endif
			},
			
			// 备案
			icpUrl(){
				let icpUrl = "https://beian.miit.gov.cn";
				// plus.runtime.openURL(icpUrl);
				uni.navigateTo({
					url: '/pages/webview/webview?url=' + icpUrl
				})
			},

			/**
			 * 路由跳转
			 */
			handleRouter(index) {
				switch (index) {
					case 0:
						// 隐私协议url
						let URL = '';
						uni.navigateTo({
							url: '/pages/webview/webview?url=' + URL
						})
						break;
					case 1:
						let URL1 = '';
						uni.navigateTo({
							url: '/pages/webview/webview?url=' + URL1
						})
						break;
					case 3:
						// 微信分享
						uni.showActionSheet({
							itemList: ['微信好友', '微信朋友圈'],
							success: (res) => {
								switch (res.tapIndex) {
									case 0:
										uni.share({
											provider: "weixin",
											scene: "WXSceneSession",
											type: 0,
											href: this.$baseConfig.portalUrl,
											title: "哇，分享标题",
											summary: "我是文本内容",
											// imageUrl: "https://www.xxx.com/166089904550.png",
											success: (res) => {
												// console.log("success:" + JSON.stringify(res));
											},
											fail: (err) => {
												// console.log("fail:" + JSON.stringify(err));
											}
										});
										break;
									case 1:
										uni.share({
											provider: "weixin",
											scene: "WXSceneTimeline",
											type: 0,
											href: this.$baseConfig.portalUrl,
											title: "哇，分享标题",
											summary: "我是文本内容",
											// imageUrl: "https://www.xxx.com/166089904550.png",
											success: (res) => {
												// console.log("success:" + JSON.stringify(res));
											},
											fail: (err) => {
												// console.log("fail:" + JSON.stringify(err));
											}
										});
										break;
									default:
										break;
								}
							},
							fail: (res) => {
								uni.showToast({
									title: '已取消分享',
									icon: 'none'
								})
							}
						});
						break;
					case 4:
						// 没有申请微信分享时，可以选择系统分享，不需要配置分享SDK，仅App支持
						uni.shareWithSystem({
						  summary: '系统分享额~',
						  href: 'https://uniapp.dcloud.io',
						  success(){
						    // 分享完成，请注意此时不一定是成功分享
						  },
						  fail(){
						    // 分享失败
						  }
						})
						break;
					default:
						break;
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		height: 100vh;
		overflow: hidden;

		.logo-wrap {
			margin-bottom: 60rpx;

			.logo {
				display: block;
				width: 160rpx;
				height: 160rpx;
				margin-top: 120rpx;
				border-radius: 16rpx;
			}

			.name {
				font-weight: bold;
				font-size: 36rpx;
				margin-top: 10px;
			}

			.version {
				font-size: 14px;
				margin-top: 16rpx;
			}
		}

		.about-footer {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			padding: 30rpx;

			.url {
				font-size: 24rpx;
				color: #0000FF;
			}

			.service {
				font-size: 24rpx;
				color: #888;
				margin-top: 30rpx;
			}

			.copyright {
				font-size: 24rpx;
				color: #888;
				text-align: center;
				margin-top: 30rpx;
				margin-bottom: 30rpx;
			}
			
			.icp-url{
				font-size: 24rpx;
				color: #888;
				text-align: center;
			}
		}
	}
</style>
